package com.springbootmybatiscurd.utils;

import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.UUID;

@Component
public class UploadFile {

    public String Upload(MultipartFile file) throws IOException {
        // 确定目标文件夹
        String fileName = file.getOriginalFilename();

        String substring = fileName.substring(fileName.lastIndexOf("."));
        String newFileName = UUID.randomUUID().toString() + substring;
        String filePath = "D:\\upload\\"+ newFileName;

        File localFile = new File(filePath);
        file.transferTo(localFile);
        // 生成网络图片
        String url="http://localhost:8080/image/"+newFileName;
        System.out.println(url);

        return url;
   }




}



